package br.com.agiledev.webscrum.action;

import java.util.ArrayList;
import java.util.List;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.framework.Controller;

import br.com.agiledev.webscrum.comuns.SugestionOption;
import br.com.agiledev.webscrum.eao.UserEAO;
import br.com.agiledev.webscrum.entity.User;

@Name("userSugestionMB")
@Scope(ScopeType.EVENT)
public class UserSugestionAction extends Controller {

    private static final long serialVersionUID = 1L;

    @In
    UserEAO userEAO;

    String valor;

    public List<SugestionOption> autocomplete(Object suggest) {

	if (suggest != null) {
	    List<User> lista = userEAO.porLoginOuNome(suggest.toString());

	    if (lista != null) {
		List<SugestionOption> sugestoes = new ArrayList<SugestionOption>(lista.size());
		for (User user : lista) {
		    sugestoes.add(new SugestionOption(user.getOid(), user.getNome(), user.getLogin()));
		}
		return sugestoes;
	    }

	}
	return null;
    }

    public String getValor() {
	return valor;
    }

    public void setValor(String valor) {
	this.valor = valor;
    }

}